package net.maku.events.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.events.convert.UserJoinActivityConvert;
import net.maku.events.entity.UserJoinActivityEntity;
import net.maku.events.service.UserJoinActivityService;
import net.maku.events.query.UserJoinActivityQuery;
import net.maku.events.vo.UserJoinActivityVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 用户参与的活动
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-03-22
*/
@RestController
@RequestMapping("events/user_join_activity")
@Tag(name="用户参与的活动")
@AllArgsConstructor
public class UserJoinActivityController {
    private final UserJoinActivityService userJoinActivityService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('events:user_join_activity:page')")
    public Result<PageResult<UserJoinActivityVO>> page(@ParameterObject @Valid UserJoinActivityQuery query){
        PageResult<UserJoinActivityVO> page = userJoinActivityService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('events:user_join_activity:info')")
    public Result<UserJoinActivityVO> get(@PathVariable("id") Long id){
        UserJoinActivityEntity entity = userJoinActivityService.getById(id);

        return Result.ok(UserJoinActivityConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('events:user_join_activity:save')")
    public Result<String> save(@RequestBody UserJoinActivityVO vo){
        userJoinActivityService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('events:user_join_activity:update')")
    public Result<String> update(@RequestBody @Valid UserJoinActivityVO vo){
        userJoinActivityService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('events:user_join_activity:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        userJoinActivityService.delete(idList);

        return Result.ok();
    }
}